package com.rederxu.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.text.TextUtils;

/**
 * @ClassName: RegularUtils
 * @Description: 正则判断工具类
 * @author wangjiangbo
 * @date 2015-5-7 下午6:51:26
 */
public class RegularUtils {

	/**
	 * 判断手機號是否合法
	 * @param mobiles
	 * @return
	 */
	public static boolean isMobileNO(String mobiles){ 
		if(TextUtils.isEmpty(mobiles)){
			return false;
		}
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");  
		Matcher m = p.matcher(mobiles);  
		return m.matches();
	}
	
	/**
	 * 判断邮箱是否合法
	 * @param email
	 * @return
	 */
	public static boolean isEmail(String email){  
		if (TextUtils.isEmpty(email)){ 
			return false;	
		}
		//Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配  
		Pattern p =  Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//复杂匹配  
		Matcher m = p.matcher(email);  
		return m.matches();  
	}
	
	/**
	 * 验证身份证号码
	 * @param idCardNumber
	 * @return
	 */
	public static boolean idCardNumber(String idCardNumber){
		if(TextUtils.isEmpty(idCardNumber)){
			return false;
		}
		Pattern p =  Pattern.compile("^\\d{15}|^\\d{17}([0-9]|X|x)$");
		Matcher m = p.matcher(idCardNumber);  
		return m.matches();  
	}
}
